1. Field of the Invention
This invention relates to virtualization and the use of virtual machines in processors and computer systems and, more particularly, to virtualizing an interrupt controller.
2. Description of the Related Art
Virtualization has been used in computer systems for a variety of different purposes. For example, virtualization may be used to execute privileged software in a “container” to prevent the privileged software from directly accessing and/or making changes to at least some of the physical machine state without first being permitted to do so by a virtual machine manager that controls the virtual machine. Such a container may prevent “buggy” or malicious software from causing problems on the physical machine. Additionally, virtualization may be used to permit two or more privileged programs to execute on the same physical machine concurrently. The privileged programs may be prevented from interfering with each other since access to the physical machine is controlled. Privileged programs may include operating systems, and may also include other software which expects to have full control of the hardware on which the software is executing. In another example, virtualization may be used to execute a privileged program on hardware that differs from the hardware expected by the privileged program.
Generally, virtualization of a processor or computer system may include providing one or more privileged programs with access to a virtual machine (the container mentioned above) over which the privileged program has full control, but the control of the physical machine is retained by the virtual machine manager. The virtual machine may include a processor (or processors), memory, and various peripheral devices that the privileged program expects to find in the machine on which it is executing. Each privileged program (and related software in some cases, such as the applications that execute on an operating system) may be referred to herein as a guest. Virtualization may be implemented in software (e.g. the virtual machine manager (VMM) mentioned above) without any specific hardware virtualization support in the physical machine on which the VMM and its virtual machines execute. However, virtualization may be simplified and/or achieve higher performance if some hardware support is provided.
In some cases, all of the peripheral devices that a guest interacts with are virtualized. That is, the VMM provides a software model of the peripheral device with which the guest interacts. The VMM interfaces to the corresponding physical device (if any) on behalf of the guest, or emulates operation of the peripheral device is no corresponding physical device exists in the computer system. Any interrupts generated by the physical device may generally be handled by the VMM as well in these cases.
In other cases, a guest may be permitted to directly interact with one or more physical peripheral devices in the computer system. If a guest directly interacts with a physical device, the guest will typically handle any interrupts generated by that device. Each guest may presume that it has full access to its own dedicated interrupt controller. A mechanism for sharing the interrupt controller among multiple guests may be needed if guests may interact directly with one or more physical peripheral devices. For example, an interrupt that is to be serviced by one guest should not be indefinitely blocked by a higher priority interrupt being serviced by another guest.
Additionally, the VMM may need to be able to inject interrupts into a guest. Typically, the VMM must determine if the guest's virtual processor is in a state that would permit the interrupt to be taken if the guest were executing on the physical machine. The checking may include examining various state that may prevent interrupts from being taken (e.g. interrupt enables), as well as examining which instructions have recently been executed in the virtual machine. If the guest's virtual processor would take the interrupt, the VMM then physically modifies the state of the guest's virtual machine. The modifications change the state of the virtual machine to the state that would result if the processor had taken an interrupt. For example, execution of the currently executing program may be suspended; some amount of state related to the currently executing program may be saved (as specified by the processor's architecture), such as the current program counter; other processor state that would be changed on taking an interrupt may be changed (e.g. processor mode registers); and the program counter may be changed to the address of the first instruction in the interrupt handler. Such direct state modification may generally be complicated and error prone, in addition to being fairly slow as a large amount of state may need to be changed. Furthermore, and in some cases a larger issue than the state modification, may be checking for whether or not interrupts are enabled. The VMM generally must intercept all operations that can change the “interrupt enables” whenever a virtual interrupt is pending, until the interrupt is finally taken. In some architectures, such as x86, numerous operations would be intercepted.